import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  
{
    path: '/auth',
    component: Layout,
    redirect: '/auth/user',
    name: 'auth',
    meta: { title: '权限管理', icon: 'auth' },
    children: [
        {
            path: 'user',
            name: 'authUser',
            component: () => import('@/views/auth/user/index'),
            meta: { title: '账号管理', icon: 'account' }
        },
        {
            path: 'role',
            name: 'authRole',
            component: () => import('@/views/auth/role/index'),
            meta: { title: '角色管理', icon: 'role' }
        },
        {
            path: 'permission',
            name: 'authPermission',
            component: () => import('@/views/auth/permission/index'),
            meta: { title: '资源管理', icon: 'menu' }
        }
    ]
},

  // 文章和素材
  {
    path: '/content',
    component: Layout,
    redirect: '/content/article',//重定向的内容
    name: 'content',
    meta: { title: '内容管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'article',
        name: 'contentArticle',//子组件名称来源按照父组件的内容写
        component: () => import('@/views/content/article/index'),
        meta: { title: '文章列表', icon: 'article' }
      },
      {
        path: 'article/add',
        name: 'contentArticleAdd',//子组件名称来源按照父组件的内容写
        component: () => import('@/views/content/article/Detail'),
        meta: { title: '增加文章', icon: 'table' , activeMenu: '/content/article'},
        hidden: true  ,
       
      },
      {
        // 编辑文章直接传递编辑的id即可
        path: 'article/edit:id',
        name: 'contentArticleEdit',//子组件名称来源按照父组件的内容写
        component: () => import('@/views/content/article/Detail'),
        meta: { title: '编辑文章', icon: 'table' ,activeMenu: '/content/article'
         },
         hidden: true 
      },
      {
        path: 'material',
        name: 'contentMaterial',//子组件名称来源按照父组件的内容写
        component: () => import('@/views/content/material/index'),
        meta: { title: '素材管理', icon: 'article',activeMenu:'/content/material' },
      },
      {
        path: 'material/add',
        name: 'contentMaterialAdd',//子组件名称来源按照父组件的内容写
        component: () => import('@/views/content/material/Detail'),
        meta: { title: '增加素材', icon: 'article',activeMenu:'/content/material'},
        hidden:true
       },
    ]
  },

  // 商品管理路由配置
  {
    path: '/product',
    component: Layout,
    redirect: '/product/list',//重定向的内容
    name: 'product',
    meta: { title: '商品管理', icon: 'goods'},

    children: [
      {
        path: 'list',
        name: 'productList', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/product/index'),
        meta: { title: '商品列表', icon: 'category' }
      },
      {
        path: '/product/edit',
        name: 'productListEdit',
        component: () => import('@/views/product/editProduct/index'),
        meta: { title: '编辑商品', icon: 'form', activeMenu:'/product/list'}
        ,hidden:true
      },
      {
        path: '/product/brand',
        name: 'productListBrand',
        component: () => import('@/views/product/brand/index'),
        meta: { title: '商品品牌', icon: 'category'}
      },
      {
        path: '/product/editbrand',
        name: 'productListBrandEdit',
        component: () => import('@/views/product/brand/editbrand'),
        meta: { title: '品牌编辑', icon: 'form',activeMenu:'/product/brand'},
        hidden:true
      },
      {
        path: '/product/category',
        name: 'productListCategory',
        component: () => import('@/views/product/category/index'),
        meta: { title: '商品分类', icon: 'category'}
      },
      {
        path: '/product/editcategory',
        name: 'productListCategoryEdit',
        component: () => import('@/views/product/component/EditCategory'),
        meta: { title: '分类编辑', icon: 'form',activeMenu:'/product/category'},
        hidden:true
      }
    ]
  },

  // 订单管理
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',//重定向的内容
    name: 'order',
    meta: { title: '订单管理', icon: 'order'},
    children:[
      {
        path: 'list',
        name: 'orderList',
        component: () => import('@/views/order/index'),
        meta: { title: '订单列表', icon: 'order'}
      },
      {
        path: '/order/edit',
        name: 'orderListEdit',
        component: () => import('@/views/order/editorder/index'),
        meta: { title: '编辑订单', icon: 'order',activeMenu:'/order/list'},
        hidden:true
      },
      {
        path: '/order/return',
        name: 'orderReturn',
        component: () => import('@/views/order/returnorder/index'),
        meta: { title: '退单列表', icon: 'order'},

      },
      {
        path: '/order/returndetail',
        name: 'orderReturnDetail',
        component: () => import('@/views/order/returnorder/detail'),
        meta: { title: '编辑退单', icon: 'order',activeMenu:'/order/return'},
        hidden:true
      },
    ]
  },


  // 地址管理
  {
    path: '/address',
    component: Layout,
    redirect: '/address/list',//重定向的内容
    name: 'address',
    meta: { title: '地址管理', icon: 'address' },
    children:[
      {
        path: 'list',
        name: 'addressList', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/address/index'),
        meta: { title: '地址列表', icon: 'address' }
      },
      {
        path: '/address/edit',
        name: 'addressListEdit', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/address/EditAddress'),
        meta: { title: '编辑地址', icon: 'address',activeMenu:'/address/list' },
        hidden:true
      },
    ]
  },

  // 营销管理
  {
    path: '/market',
    component: Layout,
    redirect: '/market/list',//重定向的内容
    name: 'market',
    meta: { title: '营销管理', icon: 'form' },
    children:[
      {
        path: 'list',
        name: 'marketList', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/market/index'),
        meta: { title: '营销列表', icon: 'form' }
      },
      {
        path: '/market/edit',
        name: 'marketListEdit', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/market/edit'),
        meta: { title: '营销编辑', icon: 'form',activeMenu:'/market/list' },
        // hidden:true
      },
    ]
  },
  // 广告管理
  {
    path: '/advertise',
    component: Layout,
    redirect: '/advertise/list',//重定向的内容
    name: 'advertise',
    meta: { title: '广告管理', icon: 'advertise' },
    children:[
      {
        path: 'list',
        name: 'advertiseList', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/advertise/index'),
        meta: { title: '广告列表', icon: 'advertise' }
      },
      {
        path: '/advertise/edit',
        name: 'advertiseListEdit', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/advertise/editadvertise'),
        meta: { title: '广告编辑', icon: 'advertise',activeMenu:'/advertise/list' },
        hidden:true
      },
    ]
  },
// 用户管理
  {
 path: '/user',
    component: Layout,
    redirect: '/user/list',//重定向的内容
    name: 'user',
    meta: { title: '用户管理', icon: 'user' },
    children:[
      {
        path: 'list',
        name: 'userList', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/user/index'),
        meta: { title: '用户列表', icon: 'user' }

      },
      {
        path: '/user/edit',
        name: 'userListEdit', // 命名 不是随便写的 一般保证唯一,使用父类命名空间+当前名字
        component: () => import('@/views/user/edituser'),
        meta: { title: '编辑用户', icon: 'user' }

      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
